﻿using System;
using System.Windows.Forms;

namespace Latin_Vocabulary_Indicator
{
    public partial class stringbox : Form
    {
        private Action<string> _backFunc;

        public stringbox(string textContent,Action<string> backFunc)
        {
            InitializeComponent();
            _backFunc = backFunc;
            title.Text = textContent;
        }
        

        private void cancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void yes_Click(object sender, EventArgs e)
        {
            if (name_.Text.Trim() == "")
            {
                MessageBox.Show("Textbox is empty.");
            }
            else
            {
                _backFunc.Invoke(name_.Text.Trim());
                Close();
            }
        }

        private void name__KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                yes_Click(null,null);
            }
            else if (e.KeyChar == (char)27)
            {
                cancel_Click(null, null);
            }

        }

        private void stringbox_FormClosing(object sender, FormClosingEventArgs e)
        {
            _backFunc.Invoke(null);
        }
    }
}
